package com.plug.service;

import com.plug.entity.PlugBackupRecord;
import com.plug.repository.PlugBackupRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 2017/1/4.
 */
@Service("plugBackupRecordService")
public class PlugBackupRecordServiceImpl implements IPlugBackupRecordService{
    @Autowired
    private PlugBackupRecordMapper plugBackupRecordMapper;
    //分页查询备份记录
    public List<Map<String, Object>> findByPageNum(int offset,int limit,String actionType){
        if(actionType==null||actionType==""){
            return plugBackupRecordMapper.findByPage(offset,limit);
        }else{

//            return plugBackupRecordMapper.selectByActionType(actionType);
            Map<String,Object> map =new HashMap<>();
            map.put("offset",offset);
            map.put("limit",limit);
            map.put("actionType",actionType);
            return plugBackupRecordMapper.pages(map);
        }



    }
    //增加备份一条记录
//    还没写具体实现
    public int saveBackupRecord(PlugBackupRecord record ){

        return plugBackupRecordMapper.insertSelective(record);
    }

    @Override
    public int saveBatch(List<PlugBackupRecord> plugBackupRecordList) {
        return plugBackupRecordMapper.insertBatch(plugBackupRecordList);
    }


    //查询记录总数
    public int findTotal(String actionType) {
        if(actionType==""||actionType==null){
            return plugBackupRecordMapper.findTotal();
        }else {
            return plugBackupRecordMapper.findSum(actionType);
        }
    }
    /**
     * 分页查询数据源
     * @param offset
     * @param limit
     * @return
     */
    public List<Map<String, Object>> pages(Integer offset, Integer limit,String actionType) {
        Map<String,Object> map =new HashMap<>();
        map.put("offset",offset);
        map.put("limit",limit);
        map.put("actionType",actionType);
        return plugBackupRecordMapper.pages(map);
    }

    /**
     *根据备份任务id查询和间隔时间查询
     * @param minute
     * @param plugContrastId
     * @return List<PlugBackupRecord>
     */
    public  PlugBackupRecord selectByBackupsAndMinuteInfo(Integer minute,Integer plugContrastId){
        return plugBackupRecordMapper.selectByBackupsAndMinuteInfo(minute,plugContrastId);
    }

    @Override
    public List<Map<String, Object>> findActionType() {
        return plugBackupRecordMapper.findActionType();
    }

    /**
     *
     * @param actionType
     * @return
     */
    public List<Map<String,Object>> selectByActionType(String actionType){
        return plugBackupRecordMapper.selectByActionType(actionType);
    }

    @Override
    public List<Map<String, Object>> test(Map<String, Object> map) {

        return plugBackupRecordMapper.pages(map);
    }
}
